<?php

/**
 * 鸡蛋白活动页面
 * 编写人   陈泽富
*/
define('IN_ECS', true);
require(dirname(__FILE__) . '/includes/init.php');

$act = !empty($_REQUEST['act'])?$_REQUEST['act']:'';

/**
 * 将鸡蛋白加入购物车(程序回收，可删除)
 *
 */
// if ($act == 'addToCart') {
//     if (empty($_SESSION['user_id'])) {
//         $result['error'] = 1;
//         $result['message'] = "请登录";
//         echo JSON()->encode($result);
//         exit;
//     }
//     /* 购物车商品信息 */
//     $cartInfo['user_id']        = $_SESSION['user_id'];
//     $cartInfo['parent_id']      = '96';
//     $cartInfo['goods_name']     = '鸡蛋白';
//     $cartInfo['goods_price']    = '5.00';
//     $cartInfo['market_price']   = '5.00';
//     $cartInfo['goods_number']   = '2';
//     $cartInfo['is_real']        = '1';
//     $cartInfo['extension_code'] = 'buyone';
//     $cartInfo['extension_id']   = '96';
//     $cartInfo['add_time']       = time();
//     $cartInfo['is_shipping']    = '1';

//     /* 查询当前用户购物车是否已有此鸡蛋白活动商品 */
//     $sql = "SELECT goods_number FROM egg_cart WHERE user_id = '{$_SESSION['user_id']}' AND parent_id = '{$cartInfo['parent_id']}'";
//     if (!$db->getOne($sql)) {
//         /* 将商品插入购物车 */
//         $sql = "INSERT INTO egg_cart (user_id, parent_id, goods_name, goods_price, market_price, goods_number, is_real, extension_code, extension_id, add_time, is_shipping) VALUES " .
//             "('{$cartInfo['user_id']}','{$cartInfo['parent_id']}','{$cartInfo['goods_name']}','{$cartInfo['goods_price']}','{$cartInfo['market_price']}','{$cartInfo['goods_number']}','{$cartInfo['is_real']}','{$cartInfo['extension_code']}','{$cartInfo['extension_id']}','{$cartInfo['add_time']}','{$cartInfo['is_shipping']}') ";
//         $db->query($sql);
//         $result['error'] = 0;
//         $result['message'] = "<span style='color: #8b0409;'>鸡蛋白</span>已成功加入购物车，<br />请带领更多与你一样不妥协的人与鸡蛋美术并肩同行。";
//         echo JSON()->encode($result);
//         exit;
//     } else {
//         $result['error'] = 0;
//         $result['message'] = "您已成功支持鸡蛋君，快提交订单完成吧！";
//         echo JSON()->encode($result);
//         exit;
//     }

// }

/* 众筹版面模块 */
$smarty->assign('page_title',      htmlspecialchars($_CFG['shop_title'])); // 页面标题
$smarty->assign('keywords',        htmlspecialchars($_CFG['shop_keywords'])); // SEO网站关键词
$smarty->assign('description',     htmlspecialchars($_CFG['shop_desc'])); // SEO网站描述

/* 当前筹集金额 */
/* 开始时间：23号09：30分 */
$sTime = strtotime('2015-08-23 09:30:00');
$time = time();
/* 截止数据时间 */
$vtime[] = strtotime('2015-08-23 09:30:00');
$vtime[] = strtotime('2015-08-23 18:00:00');
$vtime[] = strtotime('2015-08-24 18:00:00');
$vtime[] = strtotime('2015-08-25 18:00:00');
$vtime[] = strtotime('2015-08-26 18:00:00');
/* 截止数据最低要求 */
$number = array(0, 1532, 3582, 4508, 5000);
$vkey = 0; // 当前时间所在键值
foreach ($vtime as $key => $value) {
    if ($time >= $value) $vkey = $key;
}
/* 计算当前所需值 */
if ($time <= $sTime) {
    $num = 0;
} elseif ($vkey != 4) {
    $sTime = $vtime[$vkey];
    $num = $number[$vkey];
    $a = $vtime[$vkey + 1] - $sTime;
    $b = $time - $sTime;
    $n = intval(($b / $a) * ($number[$vkey+1] - $number[$vkey]));
    $num += $n;
} else {
    $num = 5000;
}

$smarty->assign('num', $num);// 参与人数;
$smarty->assign('money', $num * 10); // 筹集金额
$smarty->display('glairPoject.dwt');
